package ${package};

import ${package}.entity.JcMyInfo;
import ${package}.service.JcMyInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.concurrent.atomic.AtomicLong;

@Controller
public class GreetingController {

    private static final String template = "Hello, This is %s, and my blog is %s";
    private final AtomicLong counter = new AtomicLong();



    @Autowired
    private JcMyInfoService jcMyInfoService;

    @RequestMapping("/")
    public String index() {
        return "redirect:/myInfo";      //跳转
    }

    @RequestMapping("/myInfo")
    @ResponseBody
    public Greeting myInfo(@RequestParam(value="name", defaultValue="jc") String name,@RequestParam(value="url", defaultValue="jevoncode.com") String url) {
        JcMyInfo myInfo = jcMyInfoService.getById(1);
        if(myInfo==null) {
            return new Greeting(counter.incrementAndGet(), String.format(template, name, url));
        }else{
            return new Greeting(counter.incrementAndGet(), String.format(template, myInfo.getName(),myInfo.getBlog()));
        }
    }
}